﻿using System;
using RpcClient;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;
namespace Wedonek.RpcStore.Gateway.Service
{
        /// <summary>
        /// 任务项
        /// </summary>
        internal class AutoTaskItemService : IAutoTaskItemService
        {
                private readonly IAutoTaskItemCollect _TaskItem;
                public AutoTaskItemService (IAutoTaskItemCollect item)
                {
                        this._TaskItem = item;
                }
                /// <summary>
                /// 添加
                /// </summary>
                /// <param name="item"></param>
                /// <returns></returns>
                public Guid Add (AddTaskItem item)
                {
                        AutoTaskItem add = item.ConvertMap<AddTaskItem, AutoTaskItem> ();
                        return this._TaskItem.Add (add);
                }
                /// <summary>
                /// 删除
                /// </summary>
                /// <param name="id"></param>
                public void Delete (Guid id)
                {
                        AutoTaskItem item = this._TaskItem.Get (id);
                        this._TaskItem.Delete (item);
                }
                /// <summary>
                /// 获取任务项信息
                /// </summary>
                /// <param name="id"></param>
                /// <returns></returns>
                public AutoTaskItem Get (Guid id)
                {
                        return this._TaskItem.Get (id);
                }
                /// <summary>
                /// 获取任务下的所有任务项
                /// </summary>
                /// <param name="taskId"></param>
                /// <returns></returns>
                public TaskItem[] Gets (Guid taskId)
                {
                        return this._TaskItem.Gets (taskId);
                }
                /// <summary>
                /// 设置
                /// </summary>
                /// <param name="id"></param>
                /// <param name="set"></param>
                public void Set ([NullValidate("rpc.task.item.id.null")]Guid id, SetTaskItem set)
                {
                        AutoTaskItem item = this._TaskItem.Get (id);
                        _TaskItem.Set (item, set);
                }
                /// <summary>
                /// 禁用或启用任务项
                /// </summary>
                /// <param name="id"></param>
                /// <param name="isEnable"></param>
                public void SetIsEnable ([NullValidate ("rpc.task.item.id.null")] Guid id, bool isEnable)
                {
                        AutoTaskItem item = this._TaskItem.Get (id);
                        _TaskItem.SetIsEnable (item, isEnable);
                }
        }
}
